package com.fsquare.payment.service;

import org.broadleafcommerce.common.payment.dto.PaymentRequestDTO;
import org.broadleafcommerce.core.order.domain.Order;
import org.broadleafcommerce.core.order.domain.OrderItem;
import org.broadleafcommerce.core.payment.service.OrderToPaymentRequestDTOService;
import org.broadleafcommerce.core.payment.service.OrderToPaymentRequestDTOServiceImpl;
import org.springframework.stereotype.Service;

@Service("blOrderToPaymentRequestDTOService")
public class ExtOrderToPaymentRequestDTOServiceImpl extends OrderToPaymentRequestDTOServiceImpl implements OrderToPaymentRequestDTOService{
	
	@Override
	protected void populateDefaultLineItemsAndSubtotal(Order order, PaymentRequestDTO requestDTO) {
        requestDTO.orderSubtotal(order.getSubTotal().toString());
        
        
        for(OrderItem orderItem: order.getOrderItems()){
        	
        	requestDTO.getLineItems().add(requestDTO.lineItem()
        			.amount(orderItem.getSalePrice().getAmount().toString())
        			.name(orderItem.getName())
        			.tax(orderItem.getTaxablePrice().stringValue())
        			.itemTotal(orderItem.getTotalPrice().stringValue())
        			.category(orderItem.getCategory().getName())
        			.quantity(Integer.toString(orderItem.getQuantity())));

    	}
    }
}
